package com.cloud.pay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.common.bean.PageInfo;
import com.cloud.pay.dto.PayConfigQueryParamDTO;
import com.cloud.pay.entity.PayConfig;
import com.cloud.pay.dao.PayConfigDao;
import com.cloud.pay.service.PayConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 支付配置 服务实现类
 * </p>
 *
 * @author wenjin
 * @since 2019-12-11
 */
@Service
public class PayConfigServiceImpl extends ServiceImpl<PayConfigDao, PayConfig> implements PayConfigService {

    @Override
    public boolean exist(Integer channel, String appId, Integer ignoreId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq(PayConfig.CHANNEL, channel);
        wrapper.eq(PayConfig.APP_ID, appId);
        if (ignoreId != null) {
            wrapper.ne(PayConfig.ID, ignoreId);
        }
        if (list(wrapper).size() > 0) {
            return true;
        }
        return false;
    }

    @Override
    public PageInfo<PayConfig> selectPage(PayConfigQueryParamDTO paramDTO) {
        QueryWrapper<PayConfig> wrapper = new QueryWrapper();
        IPage page = page(new Page(paramDTO.getPageNo(), paramDTO.getPageSize()), wrapper);
        return new PageInfo(page);
    }
}
